package hmm;

import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import static hmm.Hmm.Smoothing.*;
import static org.junit.Assert.*;

public class HmmTest {

	Hmm test;
	
	@Before
	public void init() throws IOException {
		
		test = new Hmm(	new String[]{"corpus_for_debugging.txt"},
						LAPLACE);
		test.init();
	}
	
	@After
	public void end() {
		System.out.println("-----------");
	}
	
	@Test
	public void testGetStatistics() throws IOException {
		
//		System.out.println("Total num of tags:"+test.getNumOfTags());
//		System.out.println("Total num of words:"+test.getNumWords());
//		System.out.println("Total num of sentences:"+test.getNumSentences());
//		System.out.println("-----------");
		int i=0;
		for(String tag : test.getAllTags()) {
			System.out.println(tag+" at number:"+i++);
		}
		System.out.println("-----------");
//		for(String base : test.getAllBaseWords()) {
//			System.out.println(base);
//		}
//		System.out.println("-----------");
//		for(Entry<String,Integer> tag: test.getTagsToIndex().entrySet()) {
//			System.out.println("Tag:"+tag.getKey()+" at index:"+tag.getValue());
//		}
//		System.out.println("-----------");
//		for(Entry<String,Integer> tag: test.getBaseWordsToIndex().entrySet()) {
//			System.out.println("word:"+tag.getKey()+" at index:"+tag.getValue());
//		}
//		System.out.println("-----------");
		for(Entry<String,Integer> tag: test.getCourpusTagedWordCount().entrySet()) {
			System.out.println("tag:"+tag.getKey()+" with value:"+tag.getValue());
		}
	}
	
	//@Test
	public void testTransionMatrix() throws IOException {
		
		double[][] A = test.getA();
		double[] count = new double[A.length];
		Arrays.fill(count, 0);
		for (int i = 0; i < A.length; i++) {
			for (int j = 0; j < A[i].length; j++) {
				count[i]+=A[i][j];
				System.out.print(" "+A[i][j]+" ");
			}
			System.out.println();
		}
		System.out.println("-----------");
		for (int j = 0; j < A.length; j++) {
			System.out.print(" "+count[j]+" ");
		}
		System.out.println();
		System.out.println("-----------");
	}
	
	@Test
	public void testOutPutMatrix() throws IOException {

		double[][] B = test.getB();
		double[] count = new double[B.length];
		for (int i = 0; i < B.length; i++) {
			for (int j = 0; j < B[i].length; j++) {
				count[i]+=B[i][j];
				System.out.print(" "+B[i][j]+" ");
			}
			System.out.println();
		}
		System.out.println("-----------");
		for (int j = 0; j < B.length; j++) {
			System.out.print(" "+count[j]+" ");
		}
		System.out.println();
		System.out.println("-----------");
	}
	
	//@Test
	public void testInitMatrix() {
		
		double count=0;
		double[] pi = test.getPi();
		for (int i = 0; i < pi.length; i++) {
			count+=pi[i];
			System.out.print(" "+pi[i]+" ");
		}
		System.out.println("\n"+count);
		System.out.println("-----------");
	}
	
	@Test
	@Ignore
	public void testKeyHashing() {
		
		int[][] a = new int[][]{{1},{2}};
		int[][] aa = new int[][]{{1},{2}};
		
		Map<int[][],String> test = new HashMap<int[][],String>();
		test.put(a, "a");
		assertTrue(test.containsKey(aa));
	}
}
